//
//  MTCreatePartyTaskViewController.swift
//  MT
//
//  Created by ooops on 2020/5/23.
//  Copyright © 2020 张强. All rights reserved.
//

import UIKit
import Eureka
import MTCategory
import YPNavigationBarTransition
import Kingfisher
import MBProgressHUD

class UIHelper : NSObject {
    
    class func showLoading(to view: UIView, labelText: String? = nil , handler: ((_ hud: MBProgressHUD)->Void)? = nil) {
        let hud = MBProgressHUD.showAdded(to: view, animated: true)
        
            hud.label.text = labelText
        hud.bezelView.backgroundColor = UIColor.black
            hud.contentColor = UIColor.white
        handler?(hud)
    }
    
    class func hidloading(at view: UIView, showQuickMessage: String? = nil){
        MBProgressHUD.hide(for: view, animated: true)
        if showQuickMessage != nil {
            let hud = MBProgressHUD.showAdded(to: view, animated: true)
            hud.mode = .text
            hud.label.text = showQuickMessage
            hud.hide(animated: true, afterDelay: 0.5)
            hud.bezelView.backgroundColor = UIColor.black
            hud.contentColor = UIColor.white
        }
    }
    
    class func showProgress(at view: UIView, text: String?) {
        
        let hud = MBProgressHUD.showAdded(to: view, animated: true)
            hud.mode = .determinate
            hud.label.text = text
            hud.progress = 0
    }
    
    class func modifyProgressHUD(at view: UIView, progress: Float, text: String?) {
        let hud = MBProgressHUD(for: view)
        hud?.progress = progress
        hud?.label.text = text
        
        if progress >= 1 {
           hud?.hide(animated: true, afterDelay: 0.2)
        }
    }
}

extension MTCreatePartyTaskViewController: MTClubImageSelectCellDelegate {
    func clubAvatorDidChanged() {
        self.avatorUrl = nil
    }
}

// MARK: - 接口
extension MTCreatePartyTaskViewController {
    private func queryPartyGift() {
        MiTuGiftTool.pullPartyGift(provider: gift_provider, complete: { (model) in
            if model?.code == 200, let result = model?.partyResult, let id = result.id {
                self.requestParam.updateValue(id, forKey: "giftId")
                if let row: MTCreatePartyMoneyCellRow = self.form.rowBy(tag: partyMoney) as? MTCreatePartyMoneyCellRow {
                    row.cell.partyResult = result
                }
                self.partyGiftId = id
            }
        }) { (_) in
            
        }
    }
}

class MTCreatePartyTaskViewController: BaseFormViewController {
    
    let provider: MTProvider = MTProvider<MTClubApi>()
    let userProvider: MTProvider = MTProvider<UserCenterApi>()
    /// 上传
    private lazy var upload_provider: MTProvider<UploadApi> = {
        return MTProvider<UploadApi>(plugins: [])
    }()
    
    private lazy var gift_provider: MTProvider<MiTuGiftApi> = {
        return MTProvider<MiTuGiftApi>(plugins: [])
    }()
    
    private lazy var partyProvider: MTProvider<MTCreateTaskAPI> = {
        let provider = MTProvider<MTCreateTaskAPI>()
        return provider
    }()

    private var avatorUrl: String?
    
    private var redpacketDictionary: [String : String]?
    
    public typealias createClubCompleteCloseure = (Bool) -> Swift.Void
    
    private var completeCloseure: createClubCompleteCloseure?
    
    private var currentTextField: UITextField?
    /// 是否编辑模式
    private var isEditMode: Bool = false
    /// 专属礼物id
    private var partyGiftId: Int?
    private var clubId: String?
    private var partyId: String?
    public var group: JMSGGroup!
    /// 是否已经展示过异地人员酒店机票提示
    private var isShowWarning: Bool = false
    /// 编辑模式下的 partyId
    private var editModePartyId: Int?
    
    private var requestParam: [String : Any] = [
        "address": "", "allopatryAllopatryFlag": 0,
        "anonymityFlag": 0, "area": "", "city": "", "giftId": 0,
        "giftNum": 0, "inviteNum": 0,"name": "","province": "",
        "remark": "","startTime": "","subjectTypeId": 0,
        "type": 0, "href" : ""]
    
    convenience init(complete: createClubCompleteCloseure?) {
        self.init()
        self.completeCloseure = complete
    }
    
    convenience init(isEditMode: Bool, clubId: String, complete: createClubCompleteCloseure?) {
        self.init()
        self.completeCloseure = complete
        self.isEditMode = isEditMode
        self.clubId = clubId
    }
    
    
    /// 聚会任务详情进入调用
    convenience init(isEditMode: Bool, partyId: String, complete: createClubCompleteCloseure?) {
        self.init()
        self.completeCloseure = complete
        self.isEditMode = isEditMode
        self.partyId = partyId
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.backgroundColor = UIColor(hex: 0xF4F4F4)
        tableView.separatorStyle = .none
        tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
        navigationItem.leftBarButtonItem = UIBarButtonItem(customView: navBackButton)
        navigationItem.rightBarButtonItem = UIBarButtonItem(customView: publishTask)
        setupForm()
        title = isEditMode ? "编辑任务" : "发起任务"
        self.publishTask.setTitle(isEditMode ? "编辑" : "发起", for: .normal)
        if isEditMode {
            queryDetail()
        }
        
        querySubject()
        if self.partyGiftId == nil {
            queryPartyGift()
        }
    }
    
    private func queryDetail() {
        var parameters: [String : Any] = [:]
        if let id = partyId {
            parameters = ["id" : id]
        } else if clubId != nil {
            parameters = ["pushId" : clubId!]
        }
        MTCreateTaskTool.queryPartyDetail(provider: partyProvider, parameters: parameters, complete: { [weak self] (model) in
            guard let weakSelf = self else { return }
            if let m = model, m.code == 200, let detail = m.detailResult {
                weakSelf.setvalues(model: detail)
                if let id = model?.detailResult?.id {
                    weakSelf.editModePartyId = id
                }
            }
        }) { (_) in
            
        }
    }
    /// 赋值
    private func setvalues(model: MTPartyTaskListInfoModel) {
        var reqParameters: [String : Any?] = [:]
        
        reqParameters.updateValue((model.type == 1 ? "个人任务" : "商业任务"), forKey: partyType)
        
        if let area = model.area, let city = model.city, let province = model.province {
            let address = province + "-" + city + "-" + area
            reqParameters.updateValue(address, forKey: partyAddress)
        }
        
        if let detailAddress = model.address {
            reqParameters.updateValue(detailAddress, forKey: partyDetailAddress)
        }
        
        if let allopatryAllopatryFlag = model.allopatryAllopatryFlag {
            if let row: MTCreatePartySwitchCellRow = self.form.rowBy(tag: partyPlan) as? MTCreatePartySwitchCellRow {
                row.value = allopatryAllopatryFlag == 1 ? true : false
            }
        }
        
        if let anonymityFlag = model.anonymityFlag {
            if let row: MTCreatePartySwitchCellRow = self.form.rowBy(tag: partyHidden) as? MTCreatePartySwitchCellRow {
                row.value = anonymityFlag == 1 ? true : false
            }
        }
        
        
        reqParameters.updateValue("\(model.giftNum)", forKey: partyMoney)
        
        if let inviteNum = model.inviteNum {
            if let row: MTCreatePartyJoinAmountCellRow = self.form.rowBy(tag: partyJoinAmount) as? MTCreatePartyJoinAmountCellRow {
                row.value = "\(inviteNum)"
                row.cell.numberView.textField.text = "\(inviteNum)"
                row.cell.numberLabel.text = "\(inviteNum)"
            }
        }
        
        if let name = model.name {
            reqParameters.updateValue(name, forKey: partyTitle)
        }
        
        if let remark = model.remark {
            reqParameters.updateValue(remark, forKey: partyDescription)
        }
        
        if let startTime = model.startTime {
            let date = DateManager.date(dateString: startTime, format: "yyyy-MM-dd HH:mm:ss")
            reqParameters.updateValue(date, forKey: partyTime)
        }
        
        if let subjectTypeId = model.subjectTypeId {
            reqParameters.updateValue("\(subjectTypeId)", forKey: partyTheme)
            if let row: MTCreateSelectRow = self.form.rowBy(tag: partyTheme) as? MTCreateSelectRow {
                //row.reload()
                row.value = "\(subjectTypeId)"
                row.cell.contentLabel.text = model.typeName
            }
        }
        
        if let url = model.href {
            self.avatorUrl = url
        }
        
        if let row: MTClubImageSelectRow = self.form.rowBy(tag: clubAvatorKey) as? MTClubImageSelectRow {
            //row.reload()
            row.avatorImageVIew.mtSetImage(model.href, nil)
        }
        
        
        
        self.form.setValues(reqParameters)
        self.tableView.reloadData()
    }
    
    @objc private func back() {
        if self.form.validate().count > 0 {
            self.pop()
            return
        }
            
        UIAlertController.rx.show(in: self, title: "提示", message: "如果退出，内容将丢失确定要继续退出？", buttons: [.cancel("取消"), .default("确定")]).subscribe(onSuccess: { [weak self] index in
            guard let weakSelf = self else { return }
            if index == 1 {
                weakSelf.pop()
            }
        })
        .disposed(by: globalDisposedBag)
    }
    
    private func showValidationMsg(msgs: [ValidationError]) {
        MBProgressHUD_JChat.show(text: msgs.first!.msg, view: self.view)
    }
    
    private func querySubject() {
        MTCreateTaskTool.querySubject(provider: partyProvider, complete: { (model) in
            if let row: MTCreateSelectRow = self.form.rowBy(tag: partyTheme) as? MTCreateSelectRow {
                row.cell.provinces = model?.result
            }
        }) { (_) in
            
        }
    }
    
    @objc private func uploadAvator() {
        
        let validationErrors: [ValidationError] = self.form.validate()
        if validationErrors.count != 0 {
            self.showValidationMsg(msgs: validationErrors)
            return
        }
        
        let values = self.form.values()
        
        if !isEditMode && (values[clubAvatorKey] as? UIImage) == nil {
            MBProgressHUD_JChat.show(text: "请选择聚会任务封面", view: self.view)
            return
        }
        
        if values[partyTime] as? Date == nil {
            MBProgressHUD_JChat.show(text: "请先设置聚会时间", view: self.view)
            return
        }
        
        /// 验证聚会标题数据
        if let title = values[partyTitle] as? String, title.count > 7 {
            MBProgressHUD_JChat.show(text: "请输入简短标题(7个汉字以内)", view: self.view)
            return
        }
        
        if let giftNum = values[partyMoney] as? String, let count = Int(giftNum), count <= 0 {
            MBProgressHUD_JChat.show(text: "请输入大于0的任务金", view: self.view)
            return
        }
        
        if avatorUrl == nil {
            /// 拿图片
            let image: UIImage = values[clubAvatorKey] as! UIImage
            //UIHelper.showProgress(self.view, text: "正在上传聚会任务封面")
            MBProgressHUD_JChat.showProgress(self.view, text: "正在上传聚会任务封面")
            upload_provider.originRequest(.upload(image), callbackQueue: .global(), progress: { [weak self] (progressResonpse) in
                guard let weakself = self else { return }
                DispatchQueue.main.async {
                    debugPrint(Float(progressResonpse.progress * 100))
                    MBProgressHUD_JChat.modifyProgressHUD(weakself.view, progress: Float(progressResonpse.progress), text: "正在上传聚会任务封面")
                }
            }) { [weak self] (result, _) in
                guard let weakSelf = self else { return }
                switch result {
                case let .success(response):
                    if let datas = try? response.mapJSON() as? [String: Any], let code = datas["code"] as? Int {
                        if code == 200, let url = datas["result"] as? String {
                            DispatchQueue.main.async {
                                weakSelf.avatorUrl = url
                                weakSelf.createParty()
                                MBProgressHUD_JChat.dismiss(weakSelf.view)
                            }
                        } else {
                            DispatchQueue.main.async {
                                MBProgressHUD_JChat.dismiss(weakSelf.view)
                                MBProgressHUD_JChat.show(text: "图片上传失败", view: weakSelf.view)
                            }
                        }
                    }
                    break

                case .failure(_):
                    MBProgressHUD_JChat.dismiss(weakSelf.view)
                    MBProgressHUD_JChat.show(text: "图片上传失败", view: weakSelf.view)
                    break
                }
            }
        } else {
            createParty()
        }
    }
    
    // MARK: - 创建俱乐部
    @objc private func createParty() {
        self.tableView.endEditing(true)
        let values = self.form.values()
        
        if let taskType = values[partyType] as? String {
            requestParam.updateValue((taskType == "个人任务" ? 1 : 2), forKey: "type")
        }
        
        if let address = values[partyAddress] as? String {
            let array: [Substring] = address.split(separator: "-")
            requestParam.updateValue(array[2], forKey: "area")
            requestParam.updateValue(array[1], forKey: "city")
            requestParam.updateValue(array[0], forKey: "province")
        }
        
        if let detailAddress = values[partyDetailAddress] as? String {
            requestParam.updateValue(detailAddress, forKey: "address")
        }
        
        if let allopatryAllopatryFlag = values[partyPlan] as? Bool {
            requestParam.updateValue(allopatryAllopatryFlag ? 1 : 0, forKey: "allopatryAllopatryFlag")
        }
        
        if let anonymityFlag = values[partyHidden] as? Bool {
            requestParam.updateValue(anonymityFlag ? 1 : 0, forKey: "anonymityFlag")
        }
        
        if let giftNum = values[partyMoney] as? String, let count = Int(giftNum) {
            requestParam.updateValue(count, forKey: "giftNum")
        }
        
        if let inviteNum = values[partyJoinAmount] as? String, let count = Int(inviteNum) {
            requestParam.updateValue(count, forKey: "inviteNum")
        }
        
        if let name = values[partyTitle] as? String {
            requestParam.updateValue(name, forKey: "name")
        }
        
        if let remark = values[partyDescription] as? String {
            requestParam.updateValue(remark, forKey: "remark")
        }
        
        if let startTime = values[partyTime] as? Date {
            let dateString = DateManager.string(date: startTime, format: "yyyy-MM-dd HH:mm")
            requestParam.updateValue(dateString, forKey: "startTime")
        }
        
        if let subjectTypeId = values[partyTheme] as? String, let id = Int(subjectTypeId) {
            requestParam.updateValue(id, forKey: "subjectTypeId")
        }
        
        if let url = self.avatorUrl {
            requestParam.updateValue(url, forKey: "href")
        }
        
        /// 修改聚会任务信息
        if isEditMode {
            
            if let id = self.editModePartyId {
                requestParam.updateValue(id, forKey: "id")
            }
            MBProgressHUD_JChat.showLoading(self.view)
            MTCreateTaskTool.editParty(provider: self.partyProvider, parameters: requestParam, complete: { [weak self] (model) in
                guard let weakSelf = self else { return }
                if let m = model {
                    if m.code == 200 {
                        DispatchQueue.main.async {
                            MBProgressHUD_JChat.dismiss(weakSelf.view)
                            MBProgressHUD_JChat.show(text: "修改聚会任务信息成功", view: weakSelf.view)
                            DispatchQueue.main.after(1) {
                                weakSelf.completeCloseure?(true)
                                weakSelf.pop()
                            }
                        }
                    } else {
                        DispatchQueue.main.async {
                            MBProgressHUD_JChat.dismiss(weakSelf.view)
                            MBProgressHUD_JChat.show(text: "修改聚会任务信息失败", view: weakSelf.view)
                        }
                    }
                }
            }) { (error) in
                #if DEBUG
                MBProgressHUD_JChat.show(text: error.description, view: self.view)
                MBProgressHUD_JChat.dismiss(self.view)
                #endif
            }
        } else {
            MBProgressHUD_JChat.showLoading(self.view)
            MTCreateTaskTool.createParty(provider: self.partyProvider, parameters: requestParam, complete: { [weak self] (model) in
                guard let weakSelf = self else { return }
                if let m = model {
                    if m.code == 200 {
                        DispatchQueue.main.async {
                            MBProgressHUD_JChat.dismiss(weakSelf.view)
                            MBProgressHUD_JChat.show(text: "创建聚会任务信息成功", view: weakSelf.view)
                            DispatchQueue.main.async {
                                weakSelf.avatorUrl = nil
                                weakSelf.completeCloseure?(true)
                                weakSelf.pop()
                            }
                        }
                    } else {
                        if m.code == 400 {
                            if let msg = m.message {
                                MBProgressHUD_JChat.dismiss(weakSelf.view)
                                MBProgressHUD_JChat.show(text: msg, view: weakSelf.view)
                            }
                            return
                        }
                        DispatchQueue.main.async {
                            MBProgressHUD_JChat.dismiss(weakSelf.view)
                            MBProgressHUD_JChat.show(text: "发布聚会任务失败", view: weakSelf.view)
                        }
                    }
                }
            }) { (error) in
                #if DEBUG
                MBProgressHUD_JChat.dismiss(self.view)
                MBProgressHUD_JChat.show(text: error.description, view: self.view)
                #endif
            }
        }
    }
    
    // MARK: - 检查数据有效性
    private func validatorDataDictionary() {
        
        let validationErrors: [ValidationError] = self.form.validate()
        if validationErrors.count != 0 {
            publishTask.isUserInteractionEnabled = false
            publishTask.backgroundColor = UIColor.redpack.x5d5d5d
            return
        } else {
            publishTask.isUserInteractionEnabled = true
            publishTask.backgroundColor = UIColor.theme.main
        }
    }

    private func setupForm() {
            
        let section = Section()
        form +++ section
            <<< MTClubImageSelectRow(){ row in
                row.title = "活动封面上传"
                row.tag = clubAvatorKey
                row.delegate = self
            }
        let section_t = Section()
        form +++ section_t
            <<< MTPartyTypeSelectRow() { row in
                row.cell.tipString = "任务类型"
                row.cell.placeholder = "请选择"
                row.cell.height = { return 44}
                row.cell.isEditMode = true
                row.add(rule: MTClubExp(regExpr: .clubExNotNull, allowsEmpty: false, msg: "请选择聚会类型", id: nil))
                row.tag = partyType
//                row.delegate = self
            }
            <<< MTCreateSelectRow() { row in
                row.cell.tipString = "主题"
                row.cell.placeholder = "请选择"
                row.cell.height = { return 44}
                row.add(rule: MTClubExp(regExpr: .clubExNotNull, allowsEmpty: false, msg: "请选择主题", id: nil))
                row.cell.isEditMode = true
                row.tag = partyTheme
            }
            <<< MTNewClubNameCellRow(){ row in
                row.cell.tipString = "标题"
                row.cell.contentString = " "
                row.cell.placeholder = "请输入简短标题(7个汉字以内)"
                row.cell.isEditMode = true
                row.add(rule: MTClubExp(regExpr: .clubExNotNull, allowsEmpty: false, msg: "请输入简短标题", id: nil))
                row.cell.height = { return 44 }
                row.tag = partyTitle
//                row.updateCell()
            }.onChange({ (row) in
                //self.validatorDataDictionary()
            })
        let section1 = Section()
        form +++ section1
            <<< MTCreatePartyDate() { row in
                row.cell.tipText = "时间"
                row.cell.setupAccessoryView(text: nil, image: nil)
                row.cell.placeholder = "请选择"
                row.cell.height = { return 44}
                let formatter = DateFormatter()
                formatter.locale = .current
                formatter.dateFormat = "yyyy/MM/dd HH:mm"
                row.dateFormatter = formatter
                row.tag = partyTime
                row.minimumDate = Date()//.addingTimeInterval(60 * 60)
                row.maximumDate = row.value?.addingTimeInterval(60 * 60 * 24 * 30 * 12)
            }.onChange({ (row) in
                //self.validatorDataDictionary()
                //self.change()
            })
            <<< MTCreateAreaSelectRow(){ row in
                row.cell.tipString = "地点"
                row.cell.placeholder = "请选择"
//                row.tag = clubAvatorKey
                row.cell.height = { return 44}
                row.cell.isEditMode = true
                row.add(rule: MTClubExp(regExpr: .clubExNotNull, allowsEmpty: false, msg: "请选择聚会地点", id: nil))
                row.tag = partyAddress
            }
            <<< MTCreatePartyMultiCellRow(){ row in
                row.cell.tipString = "详细地址"
                row.cell.contentString = " "
                row.cell.placeholder = "请输入详细地址"
                row.cell.contentType = .editTextMutiply
                row.cell.isEditMode = true
//                row.tag = clubDescriptionKey
                row.cell.maxTextLength = 50
                row.tag = partyDetailAddress
                row.add(rule: MTClubExp(regExpr: .clubExNotNull, allowsEmpty: false, msg: "请输入详细地址", id: nil))
                //row.updateCell()
            }.onChange({ (row) in
                //self.validatorDataDictionary()
            })
        let section2 = Section()
        form +++ section2
            <<< MTCreatePartyMoneyCellRow() { row in
                row.cell.tipString = "任务金"
                row.cell.placeholder = "请输入任务金(单位 元/人)"
                row.add(rule: MTClubExp(regExpr: .clubExNotNull, allowsEmpty: false, msg: "请输入任务金", id: nil))
                row.cell.height = { return 44 }
                row.tag = partyMoney
                row.disabled = Condition(booleanLiteral: isEditMode)
                //row.updateCell()
            }.onChange({ (row) in
                //self.validatorDataDictionary()
            })
            
            <<< MTCreatePartyJoinAmountCellRow(){ row in
                row.cell.tipString = "邀请人数"
                //row.add(rule: MTClubNameRule())
                row.cell.height = { return 44 }
                row.tag = partyJoinAmount
                row.value = "2"
                if isEditMode {
                    row.cell.disableNumberView = isEditMode
                }
                //row.updateCell()
                row.add(rule: MTClubExp(regExpr: .clubExNotNull, allowsEmpty: false, msg: "请输入邀请人数", id: nil))
            }.onChange({ (row) in
                //self.validatorDataDictionary()
            })
        
        let section21 = Section()
        form +++ section21
            <<< MTCreatePartySwitchCellRow(){ row in
                row.cell.tipString = "为异地成员提供酒店机票"
                row.cell.height = { return 44 }
                row.tag = partyPlan
                //row.updateCell()
            }.onChange({ (row) in
                //self.validatorDataDictionary()
                if row.value == true, self.isShowWarning == false, self.isEditMode == false {
                    self.isShowWarning = true
                    let ruleView = MTAllopatryWarningView()
                    ruleView.frame = self.view.bounds
                    UIApplication.shared.keyWindow?.rootViewController?.view.addSubview(ruleView)
                }
            })
        
            <<< MTCreatePartySwitchCellRow(){ row in
                row.cell.tipString = "匿名发布任务"
                row.cell.height = { return 44 }
                row.tag = partyHidden
                //row.updateCell()
            }.onChange({ (row) in
                //self.validatorDataDictionary()
            })
        let section211 = Section()
        form +++ section211
            <<< MTCreatePartyMultiCellRow(){ row in
                row.cell.tipString = "详细说明"
                row.cell.contentString = " "
                row.cell.placeholder = "说出聚会的特色, 吸引更多人报名"
                row.cell.contentType = .editTextMutiply
                row.cell.isEditMode = true
                row.tag = partyDescription
                row.cell.maxTextLength = 50
                row.add(rule: MTClubExp(regExpr: .clubExNotNull, allowsEmpty: false, msg: "请输入详细说明", id: nil))
                //row.updateCell()
            }.onChange({ (row) in
                //self.validatorDataDictionary()
            })
        
        GroupTableSeparatorFix.removeFirstAndLastSeparatorLine()
    }
    
    private func caculatorTextHeight(contentString: String) -> CGFloat {
        let dict = [NSAttributedString.Key.font : PingFangSCMediumFont(14), NSAttributedString.Key.foregroundColor : UIColor.text.x9b9b9b]
        let attr: NSAttributedString = NSAttributedString(string: contentString, attributes: dict)
        
        let layout: YYTextLayout = YYTextLayout(containerSize: CGSize(width: ScreenWidth - 20, height: CGFloat.greatestFiniteMagnitude) , text: attr)!
        
        return CGSize(width: layout.textBoundingSize.width, height: layout.textBoundingSize.height).height
    }
    
    lazy var publishTask: UIButton = {
        let btn = UIButton()
        btn.setTitle("发布", for: .normal)
        btn.titleLabel?.font = PingFangSCSemiboldFont(12)
        btn.setTitleColor(UIColor.text.x161616, for: .normal)
        //btn.titleLabel.font = pingfangsc
        if let image: UIImage = UIImage.init(color: UIColor(hex: 0xffc000), size: CGSize(width: 60, height: 24))?.imageCornerRadius(12) {
            btn.setBackgroundImage(image, for: .normal)
            btn.addTarget(self, action: #selector(uploadAvator), for: .touchUpInside)
        }
//        btn.frame = CGRect(x: 0, y: 0, width: 60, height: 24)
        return btn
    }()
    
    lazy var navBackButton: UIButton = {
        let btn = UIButton(type: .custom)
        btn.setImage(UIImage(named: "nav_back"), for: .normal)
        btn.addTarget(self, action: #selector(back), for: .touchUpInside)
        return btn
    }()

}

extension MTCreatePartyTaskViewController {
    
    override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return CGFloat.leastNormalMagnitude
    }
    
    override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 11
    }
    
}

extension MTCreatePartyTaskViewController {

    override func yp_navigtionBarConfiguration() -> YPNavigationBarConfigurations {
        return [.backgroundStyleColor, .backgroundStyleOpaque, .showShadowImage]
    }
}
